#include<iostream>

using namespace std;

const int N = 2e5 + 10;
typedef long long ll;
ll a[N];

int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	ll ret = 0; ll Max = -0x3f3f3f3f3f3f;
	for (int i = 1; i <= n; i++)
	{
		if (ret >= 0)
		{
			ret += a[i];
			Max = max(Max, ret);
		}
		if(ret<0) ret = 0;
	}
	cout << Max;
	return 0;
}
